package com.woniuxy.commons.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 自动填充时间
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "repairdate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "completedate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "evaluatedate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "repairDate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "completeDate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "createdate", LocalDateTime.class, LocalDateTime.now());

        /**
         * 创建账号时
         */
        this.strictInsertFill(metaObject,"creationTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"modificationTime", LocalDateTime.class,LocalDateTime.now());
        /**
         * 新增服务指南
         */
        this.strictInsertFill(metaObject,"publishdate", LocalDateTime.class,LocalDateTime.now());
        /**
         * 登录日志
         */
        this.strictInsertFill(metaObject,"logontime", LocalDateTime.class,LocalDateTime.now());
        /**
         * 创建维修用料表
         */
        this.strictInsertFill(metaObject,"createdate", LocalDateTime.class,LocalDateTime.now());
        /**
         * 通知公告发布时间
         */
        this.strictInsertFill(metaObject,"releasedate", LocalDateTime.class,LocalDateTime.now());
        /**
         * 维修日志插入时间
         */
        this.strictInsertFill(metaObject,"operdate", LocalDateTime.class,LocalDateTime.now());
    }
 
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "completeDate", LocalDateTime.class, LocalDateTime.now());
        /**
         * 创建账号时
         */
        this.strictUpdateFill(metaObject,"modificationTime", LocalDateTime.class,LocalDateTime.now());
    }
}